package com.lone.smallmovie.utils.framework;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * 
 * <p>
 * Title: 
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: Copyright (c) 2009
 * </p>
 * <p>
 * Company:  Inc.
 * </p>
 * 
 * @author Ant 
 * @version 1.0
 */
public class SpringInitListener implements ServletContextListener {
	/**
	 * Spring loader class
	 */
	private static Log log = LogFactory.getLog(SpringInitListener.class);
	
	
	public void contextDestroyed(ServletContextEvent arg0)
	{
		log.error("SpringInitListener contextDestroyed()............... ");
	}

	/**
	 * init
	 */
	public void contextInitialized(ServletContextEvent arg0) 
	{
		if(log.isInfoEnabled())
		{
			log.info("spring loader bean..begin");
		}
		try
		{
			SystemInstance.getInstance().setAppContext(WebApplicationContextUtils
	                .getWebApplicationContext(arg0.getServletContext()));
			
			INIT.init();
			
		}
		catch (Exception ex) 
		{
			log.error("Load ApplicationContext.xml error " + ex.getMessage(),ex);
		}
		if(log.isInfoEnabled())
		{
			log.info("spring loader bean..end");
		}
	}

}
